#ifndef ABSTRACTLISTMODEL_H
#define ABSTRACTLISTMODEL_H
#include "abstractlistitem.h"
#include <QAbstractListModel>

class AbstractListModel : public QAbstractListModel {
    Q_OBJECT
    Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged)
    public:
    enum { model = Qt::UserRole + 1 }; //定义抽象类成员角色
    AbstractListModel(QObject *parent = nullptr);
    //    void addList(const AbstractList &list);
    void addListItem(AbstractListItem *item);
    void addListItems(QList<AbstractListItem *> list);
    Q_INVOKABLE void removeListItemByIndex(int index);
    int rowCount(const QModelIndex &parent = QModelIndex()) const;             //返回给定父项行数
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; //返回索引所在项给定角色的存储数据
    int count() const;
    Q_INVOKABLE AbstractListItem *hash_list(QString str);
    public slots:
    void setCount(int count);

    signals:
    void countChanged(int count);

    protected:
    QHash<int, QByteArray> roleNames() const; //返回模型的角色名
    private:
    QList<AbstractListItem *> m_abstractList; //抽象列表类容器
    QHash<QString, AbstractListItem *> m_hashList;
    int m_count{ 0 };
};

#endif // ABSTRACTLISTMODEL_H
